//
//  dlViewController.m
//  music
//
//  Created by LT on 2019/3/7.
//  Copyright © 2019 liu. All rights reserved.
//

#import "dlViewController.h"
#import "RootViewController.h"
#import "zcViewController.h"
#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height

@interface dlViewController ()<UITextFieldDelegate>
@property (nonatomic,strong)UITextField *userName;
@property (nonatomic,strong)UITextField *passWord;
@end

@implementation dlViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
}

//注册按钮的点击事件
-(void)zcOnclick{
    [self presentViewController:[zcViewController alloc] animated:YES completion:nil];
}

//登录按钮的 点击事件
-(void)dlOnclick{
     [self.navigationController pushViewController:[RootViewController alloc] animated:YES];
//    if ([self.userName.text isEqualToString:@"liu"]&&[self.passWord.text isEqualToString:@"123"]) {
//        
//        [self.navigationController pushViewController:[RootViewController alloc] animated:YES];
//        NSLog(@"账号密码c正确");
//    }else {
//        UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"提示" message:@"请输入正确的账号密码" preferredStyle:UIAlertControllerStyleAlert];
//        //创建按钮
//        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
//            //点击按钮的响应事件
//            NSLog(@"点击按钮的响应事件");
//        }];
//        //添加按钮 将按钮添加到UIAlertController对象上
//        [alertController addAction:okAction];
//
//        [self presentViewController:alertController animated:YES completion:nil];
//    }
}

//收起键盘操作
-(void)keyboardHide:(UITapGestureRecognizer*)tap{
    [self.userName resignFirstResponder];
    [self.passWord resignFirstResponder];
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSLog(@"获取到了焦点");
    return YES;
    
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if ([string isEqualToString:@"\n"]) {
        NSLog(@"获取到了焦点，点击return");
        return NO;
    }
    return YES;
}

//隐藏导航栏
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

//隐藏导航栏
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = YES;
}

//初始化页面ui
-(void)initUI{
    UIImageView *backImage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"登录页面1"]];
    backImage.frame=CGRectMake(0, 0, kWidth, kHeight);
    [self.view addSubview:backImage];
    
    UIView *shadowView=[[UIView alloc]initWithFrame:CGRectMake((kWidth-kWidth*0.75)/2, kHeight*0.17, kWidth*0.75, kHeight*0.5)];
    shadowView.backgroundColor=[UIColor whiteColor];
    shadowView.layer.cornerRadius=15;
    shadowView.layer.shadowColor=[UIColor blackColor].CGColor;
    shadowView.layer.shadowOffset=CGSizeMake(0, 0);
    shadowView.layer.shadowOpacity=0.2;   //阴影的透明度
    shadowView.layer.shadowRadius=15;
    [self.view addSubview:shadowView];
    
    UILabel *dlLabel=[[UILabel alloc]initWithFrame:CGRectMake((kWidth-kWidth*0.5)/2, kHeight*0.2, kWidth*0.5, kHeight*0.05)];
    dlLabel.text=@"登录界面";
    dlLabel.font=[UIFont systemFontOfSize:22];
    dlLabel.textAlignment=NSTextAlignmentCenter;
    dlLabel.textColor=[UIColor redColor];
    [self.view addSubview:dlLabel];
    
    
    self.userName=[[UITextField alloc]initWithFrame:CGRectMake((kWidth-kWidth*0.5)/2, kHeight*0.3, kWidth*0.5, kHeight*0.05)];
    self.userName.borderStyle=UITextBorderStyleRoundedRect ;
    self.userName.placeholder=@"请输入账户名";
    [self.view addSubview:self.userName];
    
    self.passWord=[[UITextField alloc]initWithFrame:CGRectMake((kWidth-kWidth*0.5)/2, kHeight*0.37, kWidth*0.5, kHeight*0.05)];
    self.passWord.borderStyle=UITextBorderStyleRoundedRect ;
    self.passWord.placeholder=@"请输入密码";
    self.passWord.secureTextEntry=YES;//设置隐藏密码
    [self.view addSubview:self.passWord];
    
    UIButton *dlButton=[[UIButton alloc]initWithFrame:CGRectMake((kWidth-kWidth*0.5)/2, kHeight*0.47, kWidth*0.5, kHeight*0.05)];
    dlButton.backgroundColor=[UIColor redColor];
    dlButton.tintColor=[UIColor whiteColor];
    //dlButton.titleLabel.text=@"点击登录";
    [dlButton setTitle:@"登录" forState:UIControlStateNormal];
    dlButton.titleLabel.textColor=[UIColor blackColor];
    dlButton.layer.cornerRadius=15;
    [dlButton addTarget:self action:@selector(dlOnclick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:dlButton];
    
    UIButton *zcButton=[[UIButton alloc]initWithFrame:CGRectMake((kWidth-kWidth*0.5)/2, kHeight*0.54, kWidth*0.5, kHeight*0.05)];
    zcButton.backgroundColor=[UIColor redColor];
    zcButton.tintColor=[UIColor whiteColor];
    //dlButton.titleLabel.text=@"点击登录";
    [zcButton setTitle:@"注册" forState:UIControlStateNormal];
    zcButton.titleLabel.textColor=[UIColor blackColor];
    zcButton.layer.cornerRadius=15;
    [zcButton addTarget:self action:@selector(zcOnclick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:zcButton];
    
    self.userName.delegate=self;
    self.passWord.delegate=self;
    
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
    //设置成NO表示当前控件响应后会传播到其他控件上，默认为YES。
    tapGestureRecognizer.cancelsTouchesInView = NO;
    //将触摸事件添加到view上
    [self.view addGestureRecognizer:tapGestureRecognizer];
    
    
}


@end
